package core;
 
import java.awt.Dimension;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
 
public class SimpleGame extends BasicGame{
	
	private Player player = new Player();
	private Platform platform = new Platform();
	private float speed = 2.0f;
	
    public SimpleGame()
    {
        super("Canabalt Clone");
        
    }
 
    @Override
    public void init(GameContainer gc) throws SlickException {
    	
    	player.setY(0);
        player.setX(100);
        
        platform.setY(250);
        platform.setX(100);
        
    	player.setSprite(new Image("core/655935.png"));
    	player.setBounds(new Dimension(32,32));
    	platform.setBounds(new Dimension(32,32));
    	platform.setSprite(new Image("core/655935.png"));
    	
    }
 
    @Override
    public void update(GameContainer gc, int delta) 
			throws SlickException     
    {

    	if(speed < 25)
    		speed = speed + speed*0.10f;
    	player.setY(player.getY() + speed);
    	if(player.doCollide(platform)) {
    		
    		for(int i = 0; i < (int)speed; i++) {
    			player.setY(player.getY() - 1);
    			if(!player.doCollide(platform))
    				break;
    		}
    		
    		speed = 0;
    	}
    	
    }
 
    public void render(GameContainer gc, Graphics g) 
			throws SlickException 
    {
    	g.drawImage(player.getSprite(), player.getX(), player.getY());
    	g.drawImage(platform.getSprite(), platform.getX(), platform.getY());
    }
 
    public static void main(String[] args) 
			throws SlickException
    {
         AppGameContainer app = 
			new AppGameContainer(new SimpleGame());
 
         app.setDisplayMode(800, 600, false);
         app.setTargetFrameRate(58);
         app.setVSync(true);
         app.start();
    }
}